import {Component, OnInit} from '@angular/core';
import {ActivatedRoute} from '@angular/router';
import {NavController, ToastController} from '@ionic/angular';
import {HttpService} from '../../services/http.service';
import {BasePage} from '../../common/basePage';
import {UrlAndOPT} from '../../common/url-and-opt.enum';

@Component({
  selector: 'app-user-lend-bill-detail',
  templateUrl: './user-lend-bill-detail.page.html',
  styleUrls: ['./user-lend-bill-detail.page.scss'],
})
export class UserLendBillDetailPage extends BasePage implements OnInit {

  data: any = {};
  totalPeriod: number;

  constructor(
    public navCtrl: NavController,
    public toastCtrl: ToastController,
    private routeInfo: ActivatedRoute,
    private service$: HttpService
  ) {
    super(navCtrl, toastCtrl);
  }

  ngOnInit() {
    if (this.routeInfo.snapshot.params['data']) {
      this.data = JSON.parse(this.routeInfo.snapshot.params['data']);
      this.totalPeriod = this.data['totalPeriod'];
    } else if (this.routeInfo.snapshot.params['bidId'] && this.routeInfo.snapshot.params['billInvestId']) {
      this.service$.doRequest(UrlAndOPT.auth_user_lend_bill_detail, {
        bidId: this.routeInfo.snapshot.params['bidId'],
        billInvestId: this.routeInfo.snapshot.params['billInvestId']
      })
        .subscribe(obj => {
          if (obj) {
            this.data = obj['billInvestInfo'];
            this.totalPeriod = obj['totalPeriod'];
          }
        });
    }
  }

}
